package com.rico.kok.service.editor;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rico.kok.entity.editor.Editor;
import com.rico.kok.tool.PostUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class UploadImageServiceImpl implements UploadImageService {

    @Autowired
    private PostUtils postUtils;

    @Override
    public JSONObject uploadImg(MultipartFile file) {
        JSONObject json=null;
        try {
            //调用图片上传的方法
            String res=postUtils.uploadPostPicture(file);
            Editor editor=new Editor();
            editor.setErrno(0);
            HashMap<String,String> map=new HashMap();
            map.put("url",res);
            map.put("alt","alt");
            Map<String,String>[] maps=new Map[]{map};
            editor.setData(maps);
            json= (JSONObject) JSON.toJSON(editor);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(json);
        return json;
    }
}
